<?php
defined('BASEPATH') or exit('No direct script access allowed');

//导入导出Excel业务逻辑
class ExportExcelService extends TP_Service {

  private $action_whiteList = array("__construct", "doTransaction", "get_instance");
  public function __construct() {
    parent::__construct();
    $this->load->library('PHPExcel/PHPExcel');
    $this->load->library('PHPExcel/PHPExcel/IOFactory');
  }

  /**  
   * 导出excel表
   * @access public 
   * @param  $arraylist   导出数据列
   * @param  $name      导出excel名称
   * @param  $tableth     表头名称  *
   * @param  $t   表头从第n行开始导出 
   * @param  $i  表数据从第n行开始导出
   * @param  $title   表标题,不传默认为空
   * @autor  xy
   */
  public function export_excel($arraylist, $name, $tableth, $t, $i, $title = '') {
    $excel = new PHPExcel();
    $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(15);

    //获取标题
    $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '1:' . PHPExcel_Cell::stringFromColumnIndex(6) . '1');
    $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '1', $title);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    //表头
    $table_th = explode(',', $tableth);
    for ($m = 0; $m < count($table_th); $m++) {
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($m) . ($t), $table_th[$m]);
    }

    //表数据
    foreach ($arraylist as $k => $v) {
      $v = array_values($v);  //重新排列数组
      for ($column = 0; $column < count($v); $column++) {
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($column) . $i, $v[$column]);
      }
      $i++;
    }

    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(9) . ($i - 1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(0) . ($i - 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    $write = new PHPExcel_Writer_Excel2007($excel);
    $director = "upload/export/" . date('Ymd', time()) . "/";
    if (!file_exists($director)) {
      //检查是否有该文件夹，如果没有就创建，并给予最高权限
      mkdir($director, 0777);
    }
    $file_name = $name . '.xlsx';
    $write->save($director . iconv('utf-8', 'gb2312', $file_name));

    return array('director' => $director, 'file_name' => $file_name);
  }


  /**  
   * excel表导入
   * @access public 
   * @param  $pathArray   导入文件地址(必传)
   * @param  $begin  导入开始列  默认A列开始导入(非必传)
   * @param  $end   导入结束列  (非必传)
   * @param  $row  第N行开始导入,默认第二行开始导入(非必传)
   * @autor  xy
   */
  public function importexcel($pathArray, $end = '', $begin = 'A', $row = 2, $is_function = false) {

    try {
      $inputFileType = IOFactory::identify($pathArray['path']);
      $objReader = IOFactory::createReader($inputFileType);
      $objPHPExcel = $objReader->load($pathArray['path']);
    } catch (Exception $e) {
      die('加载文件发生错误："' . pathinfo($pathArray['path'], PATHINFO_BASENAME) . '": ' . $e->getMessage());
    }
    // 确定要读取的sheet
    $sheet = $objPHPExcel->getSheet(0);
    $highestRow = $sheet->getHighestRow();
    if ($end == '') {
      $highestColumn = ch2int($sheet->getHighestColumn());
    } else {
      $highestColumn = ch2int($end);
    }


    $excel_data = array();
    $user_array = array();
    for ($currentRow = $row; $currentRow <= $highestRow; $currentRow++) {
      for ($currentColumn = ch2int($begin); $currentColumn <= $highestColumn; $currentColumn++) {
        if ($is_function) {
          $getValue = $objPHPExcel->getActiveSheet()->getCell(chrnum($currentColumn) . $currentRow)->getFormattedValue();
        } else {
          $getValue = $objPHPExcel->getActiveSheet()->getCell(chrnum($currentColumn) . $currentRow)->getValue();
        }
        $excel_data[chrnum($currentColumn)] = trim($getValue);
      }
      $user_array[] =  $excel_data; //array_values($excel_data);

    }
    return $user_array;
  }



  /**  
   * 导出excel表
   * @access public 
   * @param  $arraylist   导出自定义数据列
   * @param  $name      导出excel名称
   * @param  $tableth     表头名称  *
   * @param  $t   表头从第n行开始导出 
   * @param  $i  表数据从第n行开始导出
   * @param  $title   表标题,不传默认为空
   * @autor  xy
   */
  public function export_excel1($arraylist, $name, $tableth, $t, $i, $type) {
    $zipDir = "upload/ExportZip/";
    if (!file_exists($zipDir)) {
      //检查是否有该文件夹，如果没有就创建，并给予最高权限
      mkdir($zipDir, 0777);
    }
    $zipDir = "upload/ExportZip/" . date('Ymd', time()) . "/";
    if (!file_exists($zipDir)) {
      //检查是否有该文件夹，如果没有就创建，并给予最高权限
      mkdir($zipDir, 0777);
    }
    //  $excel->createSheet();
    // $excel->setActiveSheetIndex(0);
    // $excel->getActiveSheet()->setTitle($value['examine_classroom']);

    // log_pri($arraylist);
    $styleThinBlackBorderOutline = array(
      'borders' => array(
        'allborders' => array( //设置全部边框
          'style' => \PHPExcel_Style_Border::BORDER_THIN //粗的是thick
        ),

      ),
    );
    foreach ($arraylist as $key => $value) {
      $excel = new PHPExcel();
      $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(15);
      // $excel->getActiveSheet()->getStyle("A1:F26")->applyFromArray($styleThinBlackBorderOutline);

      //获取标题
      // 第一行
      $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '1:' . PHPExcel_Cell::stringFromColumnIndex(5) . '1');
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '1', $value['title']);
      // style样式
      $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(false);
      $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(12);
      $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

      // 第二行
      $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '2:' . PHPExcel_Cell::stringFromColumnIndex(5) . '2');
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '2', $value['fu_title']);
      // style样式
      $excel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
      $excel->getActiveSheet()->getStyle('A2')->getFont()->setBold(false);
      $excel->getActiveSheet()->getStyle('A2')->getFont()->setSize(12);
      $excel->getActiveSheet()->getStyle('A2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);


      // 第3️三行
      $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '3:' . PHPExcel_Cell::stringFromColumnIndex(5) . '3');
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '3', $value['remark']);
      // style样式
      $excel->getActiveSheet()->getStyle('A3')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
      $excel->getActiveSheet()->getStyle('A3')->getFont()->setBold(false);
      $excel->getActiveSheet()->getStyle('A3')->getFont()->setSize(12);
      // $excel->getActiveSheet()->getStyle('A3')->getAlignment()->setVertical(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);

      //表头
      $table_th = explode(',', $tableth);
      for ($m = 0; $m < count($table_th); $m++) {
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($m) . ($t), $table_th[$m]);
      }

      // log_pri(count($value['studentInfo']));

      //表数据
      $v[$key] = array();
      for ($j = 0; $j < count($value['studentInfo']); $j++) {
        $v[$key][$j] = array_values($value['studentInfo'][$j]);  //重新排列数组
      }
      $index = $i;
      for ($b = 0; $b < count($v[$key]); $b++) {
        for ($column = 0; $column < count($table_th); $column++) {
          $excel->setActiveSheetIndex()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($column) . $index, $v[$key][$b][$column]);
        }
        $index++;
      }
      $excel->getActiveSheet()->getStyle("A1:F" . ($index - 1))->applyFromArray($styleThinBlackBorderOutline);

      //  $director = "upload/export/" . date('Ymd', time()) . "/";
      // if (!file_exists($director)) {
      //     //检查是否有该文件夹，如果没有就创建，并给予最高权限
      //     mkdir($director, 0777);
      // }

      $write = new PHPExcel_Writer_Excel2007($excel);
      if ($type == 1) {
        $file_name = $value['examine_classroom'] . '.xlsx';
      } else {
        $file_name = $value['interview_classroom'] . '.xlsx';
      }

      // $title = iconv("utf-8", "gb2312", $file_name);
      // header("Content-Disposition:attachment;filename=".$title.".xlsx");   

      // log_pri($file_name);
      $write->save($zipDir . $file_name);

      ob_flush();
      $excelpath[] = $zipDir . $file_name;
    }

    //打包成压缩包


    //这里需要注意该目录是否存在，并且有创建的权限
    if ($type == 1) {
      $zipname = $zipDir . "/招生候考室" . $name . ".zip";
    } else {
      $zipname = $zipDir . "/招生面试室" . $name . ".zip";
    }


    //这是要打包的文件地址数组
    // $files = array("mypath/test1.txt","mypath/test2.pdf");
    $zip = new ZipArchive();
    $res = $zip->open($zipname, ZipArchive::CREATE);
    if ($res === TRUE) {
      foreach ($excelpath as $file) {
        //这里直接用原文件的名字进行打包，也可以直接命名，需要注意如果文件名字一样会导致后面文件覆盖前面的文件，所以建议重新命名
        $new_filename = substr($file, strrpos($file, '/') + 1);
        $zip->addFile($file, $new_filename);
      }
    }
    //关闭文件
    $zip->close();

    foreach ($excelpath as $f) {
      unlink($f);
    }

    return $zipname;
  }


  /**  
   * 导出excel表
   * @access public 
   * @param  $arraylist   导出数据列
   * @param  $name      导出excel名称
   * @param  $tableth     表头名称  *
   * @param  $t   表头从第n行开始导出 
   * @param  $i  表数据从第n行开始导出
   * @param  $title   表标题,不传默认为空
   * @autor  xy
   */
  public function export_excel2($arraylist, $name, $tableth, $t, $i, $title = '', $X = 'A', $Y = 'Z') {
    ini_set('memory_limit', '-1');
    $excel = new PHPExcel();
    $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);

    //获取标题
    $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '1:' . PHPExcel_Cell::stringFromColumnIndex(6) . '1');
    $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '1', $title);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $styleThinBlackBorderOutline = array(
      'borders' => array(
        'allborders' => array( //设置全部边框
          'style' => \PHPExcel_Style_Border::BORDER_THIN //粗的是thick
        ),

      ),
    );

    //表头样式
    $excel->getActiveSheet()->getStyle($X . $t . ':' . $Y . $t)->applyFromArray($styleThinBlackBorderOutline);
    $excel->getActiveSheet()->getStyle($X . $t . ':' . $Y . $t)->getFont()->setBold(true);
    $excel->getActiveSheet()->getStyle($X . $t . ':' . $Y . $t)->getFont()->setSize(9);
    $excel->getActiveSheet()->getRowDimension($t)->setRowHeight(25);
    $excel->getActiveSheet()->getStyle($X . $t . ':' . $Y . $t)->getFill()->getStartColor()->setARGB('FFAA33');
    $excel->getActiveSheet()->getStyle($X . $t . ':' . $Y . $t)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);

    //表头
    $table_th = explode(',', $tableth);
    for ($m = 0; $m < count($table_th); $m++) {
      $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($m) . ($t))->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($m) . ($t), $table_th[$m]);
    }

    //表数据
    $arr_new = array();
    $i_arr = array();
    foreach ($arraylist as $k => $v) {
      // log_pri($v);
      $arr_new[$i] = $v;
      $i_arr[] = $i;
      $v = array_values($v);  //重新排列数组           
      for ($column = 0; $column < count($v); $column++) {
        // $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($column).$i,$v[$column])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);   
        //内容
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($column) . $i, $v[$column])->getStyle($X . $i . ':' . $Y . $i)->applyFromArray($styleThinBlackBorderOutline);
        $excel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
      }
      $i++;
    }

    //给特殊学生成绩标注背景颜色&& $arr_new[$value]['enroll_state'] != $arr_new[$value+1]['enroll_state']
    foreach ($i_arr as $key => $value) {
      if (isset($arr_new[$value + 1])) {
        if ($arr_new[$value]['chinese'] == $arr_new[$value + 1]['chinese'] && $arr_new[$value]['mathematics'] == $arr_new[$value + 1]['mathematics'] && $arr_new[$value]['english'] == $arr_new[$value + 1]['english'] && $arr_new[$value]['politics'] == $arr_new[$value + 1]['politics'] && $arr_new[$value]['history'] == $arr_new[$value + 1]['history'] && $arr_new[$value]['geography'] == $arr_new[$value + 1]['geography'] && $arr_new[$value]['physics'] == $arr_new[$value + 1]['physics'] && $arr_new[$value]['chemistry'] == $arr_new[$value + 1]['chemistry'] && $arr_new[$value]['biology'] == $arr_new[$value + 1]['biology'] && $arr_new[$value]['technology'] == $arr_new[$value + 1]['technology'] && $arr_new[$value]['gk_total_score'] == $arr_new[$value + 1]['gk_total_score'] && $arr_new[$value]['synthesize'] == $arr_new[$value + 1]['synthesize'] && $arr_new[$value]['total_score'] == $arr_new[$value + 1]['total_score'] && $arr_new[$value]['major'] == $arr_new[$value + 1]['major'] && $arr_new[$value]['characters'] == $arr_new[$value + 1]['characters'] && $arr_new[$value]['motion'] == $arr_new[$value + 1]['motion'] && $arr_new[$value]['art_cultivation'] == $arr_new[$value + 1]['art_cultivation'] && $arr_new[$value]['creative_practice'] == $arr_new[$value + 1]['creative_practice']) {
          $excel->getActiveSheet()->getStyle($X . $value . ':' . $Y . $value)->getFill()->getStartColor()->setARGB('FF8888');
          $excel->getActiveSheet()->getStyle($X . $value . ':' . $Y . $value)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
          $excel->getActiveSheet()->getStyle($X . ($value + 1) . ':' . $Y . ($value + 1))->getFill()->getStartColor()->setARGB('FF8888');
          $excel->getActiveSheet()->getStyle($X . ($value + 1) . ':' . $Y . ($value + 1))->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
        }
      }
    }

    // log_pri($arr_new);

    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(9) . ($i - 1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(0) . ($i - 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    $write = new PHPExcel_Writer_Excel2007($excel);
    $director = "upload/export/" . date('Ymd', time()) . "/";
    if (!file_exists($director)) {
      //检查是否有该文件夹，如果没有就创建，并给予最高权限
      mkdir($director, 0777);
    }
    $file_name = '学生最终名单' . $name . '.xlsx';
    // $write->save($director.iconv('utf-8', 'gb2312', $file_name));
    $write->save($director . $file_name);

    return array('director' => $director, 'file_name' => $file_name);
  }


  /**  
   * 导出excel表
   * @access public 
   * @param  $arraylist   导出数据列
   * @param  $name      导出excel名称
   * @param  $tableth     表头名称  *
   * @param  $t   表头从第n行开始导出 
   * @param  $i  表数据从第n行开始导出
   * @param  $title   表标题,不传默认为空
   * @autor  xy
   */
  public function export_excel3($arraylist, $name, $tableth, $t, $i, $title = '') {
    $excel = new PHPExcel();
    $excel->getActiveSheet()->getDefaultColumnDimension()->setWidth(20);

    //获取标题
    $excel->getActiveSheet()->mergeCells(PHPExcel_Cell::stringFromColumnIndex(0) . '1:' . PHPExcel_Cell::stringFromColumnIndex(6) . '1');
    $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex(0) . '1', $title);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
    $excel->getActiveSheet()->getStyle('A1')->getFont()->setSize(16);
    $excel->getActiveSheet()->getStyle('A1')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);

    $styleThinBlackBorderOutline = array(
      'borders' => array(
        'allborders' => array( //设置全部边框
          'style' => \PHPExcel_Style_Border::BORDER_THIN //粗的是thick
        ),

      ),
    );

    //表头样式
    $excel->getActiveSheet()->getStyle('A' . $t . ':I' . $t)->applyFromArray($styleThinBlackBorderOutline);
    $excel->getActiveSheet()->getStyle('A' . $t . ':I' . $t)->getFont()->setBold(true);
    $excel->getActiveSheet()->getStyle('A' . $t . ':I' . $t)->getFont()->setSize(9);
    $excel->getActiveSheet()->getRowDimension($t)->setRowHeight(25);
    // $excel->getActiveSheet()->getStyle( 'A'.$t.':M'.$t)->getFill()->getStartColor()->setARGB('FFAA33');
    // $excel->getActiveSheet()->getStyle( 'A'.$t.':M'.$t)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);

    //表头
    $table_th = explode(',', $tableth);
    for ($m = 0; $m < count($table_th); $m++) {
      $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($m) . ($t))->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
      $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($m) . ($t), $table_th[$m]);
    }

    //表数据
    $arr_new = array();
    $i_arr = array();
    foreach ($arraylist as $k => $v) {
      // log_pri($v);
      $arr_new[$i] = $v;
      $i_arr[] = $i;
      unset($v['is_different']); //移除掉多余的
      unset($v['is_row']); //移除掉多余的
      $v = array_values($v);  //重新排列数组     
      for ($column = 0; $column < count($v); $column++) {
        // $excel->getActiveSheet()->getStyle(PHPExcel_Cell::stringFromColumnIndex($column).$i,$v[$column])->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);   
        //内容
        $excel->getActiveSheet()->setCellValue(PHPExcel_Cell::stringFromColumnIndex($column) . $i, $v[$column])->getStyle('A' . $i . ':M' . $i)->applyFromArray($styleThinBlackBorderOutline);
        $excel->getActiveSheet()->getRowDimension($i)->setRowHeight(25);
      }
      $i++;
    }

    //给特殊学生成绩标注背景颜色&& $arr_new[$value]['enroll_state'] != $arr_new[$value+1]['enroll_state']
    foreach ($i_arr as $key => $value) {
      if ($arr_new[$value]['is_different'] == 1) {
        $excel->getActiveSheet()->getStyle('A' . $value . ':M' . $value)->getFill()->getStartColor()->setARGB('FFFF77');
        $excel->getActiveSheet()->getStyle('A' . $value . ':M' . $value)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
      }

      foreach ($arr_new[$value]['is_row'] as $key => $value1) {
        switch ($value1) {
          case 'A':
            $excel->getActiveSheet()->getStyle('A' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'B':
            $excel->getActiveSheet()->getStyle('B' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'C':
            $excel->getActiveSheet()->getStyle('C' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'D':
            $excel->getActiveSheet()->getStyle('D' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'E':
            $excel->getActiveSheet()->getStyle('E' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'F':
            $excel->getActiveSheet()->getStyle('F' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'G':
            $excel->getActiveSheet()->getStyle('G' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'H':
            $excel->getActiveSheet()->getStyle('H' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
          case 'I':
            $excel->getActiveSheet()->getStyle('I' . $value)->getFont()->setBold(true)->setSize(14)->getColor()->setRGB('FF0000');
            break;
        }
      }
    }

    // log_pri($arr_new);

    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(9) . ($i - 1))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $excel->getActiveSheet()->getStyle('A1:' . PHPExcel_Cell::stringFromColumnIndex(0) . ($i - 1))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

    $write = new PHPExcel_Writer_Excel2007($excel);
    $director = "upload/export/" . date('Ymd', time()) . "/";
    if (!file_exists($director)) {
      //检查是否有该文件夹，如果没有就创建，并给予最高权限
      mkdir($director, 0777);
    }
    $file_name = '浙江工业职业技术学院2020年五年制升学转入录取名册数据库' . $name . '.xlsx';
    // $write->save($director.iconv('utf-8', 'gb2312', $file_name));
    $write->save($director . $file_name);

    return array('director' => $director, 'file_name' => $file_name);
  }
}
